import os
import sysconfig
import re


def juOS():
	mac_color = color("black")
	info_platform =  sysconfig.get_platform()
	try:
	 	os  = re.search(r"mac",info_platform).group()
	except AttributeError:
	 	try:
	 		os = re.search(r"[wW]down[sS]",info_platform).group()
	 	except AttributeError:
	 		os = re.search(r"Linux",info_platform).group()
	return mac_color.get_color(os) 		
class color:
	def __init__(self,color_i):
		self.color = color_i
	def get_color(self,st):
		if self.color == "green":
			return  "%s[35;36m%s%s[0m" %(chr(27),st,chr(27))
		elif self.color == "purple":
			return "%s[35;35m%s%s[0m" %(chr(27),st,chr(27))
		elif self.color == "black":
			return  "%s[5;30m%s%s[0m" %(chr(27),st,chr(27))


def math_bin(x):
	a = []
	a_conut= 0
	b = []
	c =int (x)
	per = x - int(x)

	while c>=2:
		a_conut = len(a)
		if a_conut % 5 == 0:
			a.append(" ")

		a.append(c%2)
		b.append(c/2)
		c =  c /2
		if c == 1:
			a.append(1)
	
	a.reverse()
	a.append(".")

	for i in range(5):
		a.append(for_per(per))
		per =  (per*2) - int(per * 2 )

	#a.reverse()
	print a
	print b
	result = re_to_string(a)

	co = color("green")
	result = co.get_color(result)
	print "\n result > %s" %result

def for_per(x):
	m = x - int(x)
	if m != 0:
		return (int (m *2))
	else :
		return 0
def re_to_string(x):
	result = ""
	for i in x:
		result += str(i)
	return result


if __name__ == "__main__":
	mode = ""
	colorful = color("purple")
	mode = juOS()
	os.system("clear")
	print colorful.get_color("\b================Start in %s"%mode) + "%s[35;35m==========================%s[0m\n" %(chr(27),chr(27)) 
	print "\b print %s[31;31m q/Q%s[0m to exit this process\n" %(chr(27),chr(27))
	a= ""
	while a != "q" or a != "Q": 
		if not (a == "q" or a == "Q "):

			a = raw_input("number : " )
			try:
				a= float (a)
			except ValueError:
				print "exit sucessful\n"
				exit(0)
			math_bin(a)
		else :
			break

